package fr.cephb.joperon.webapp.tag;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;



public class Comic  extends BodyTagSupport
	{
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH=640;
	private static final int DEFAULT_HEIGHT=400;
	/** svg Width */
	private int width=DEFAULT_WIDTH;
	/** svg Height */
	private int height=DEFAULT_HEIGHT;
	
	/***
	 * SVGTitle
	 */
	public Comic()
		{
		}
	
	@Override
	public int doStartTag() throws JspException
		{
		return EVAL_BODY_BUFFERED;
		}
	
	@Override
	public int doEndTag() throws JspException {
		try {
			String content= null;
			if(this.bodyContent!=null)
				{
				content= this.bodyContent.getString();
				}
			
			if(content!=null)
				{
				super.pageContext.getOut().print(
					"<img  src=\"http://localhost:8080/joperon/dymo?text=" +
					URLEncoder.encode(content,"UTF-8")+"&width="+width+"&height="+height+
					"\"/>"
					);
				}
			} 
		catch (IOException err)
			{
			throw new JspException(err);
			}
		return EVAL_PAGE;
		}
	
	
	@Override
	public void release() {
		this.width=DEFAULT_WIDTH;
		this.height=DEFAULT_HEIGHT;
		}
	
	public void setWidth(int width) {
		this.width = width;
	}
	
	public void setHeight(int height) {
		this.height = height;
	}
	
	}
